<template>
    <div class="knowledge">
      <!--热门视频title-->
      <div>
        <span class="card-title-text ellipsis">热门视频</span>
      </div>
      <!--热门视频content-->
      <div class="content">
        <div v-for="(item,index) in KnowledgeData.slice(0,5)">
          <div class="card_list">
            <!--img-->
            <div class="img_list">
              <img  :src="'static/img/'+item.img" alt="">
            </div>
            <!--text-->
            <div class="title_text">
              <span>{{item.title}}</span>
            </div>
            <div class="text_bom">
              <span class="b1 el-icon-video-play">{{item.watch}}万</span>
              <span class="b2 el-icon-user">{{item.body}}</span>
            </div>
          </div>
        </div>

      </div>
      <!--知识title-->
      <div class="title">
        <span class="card-title-text ellipsis">更多知识</span>
      </div>
      <!--知识content-->
      <div class="content bom1">
        <div v-for="(item , index) in tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)">
          <div class="card_list">
            <!--img-->
            <div class="img_list">
              <img  :src="'static/img/'+item.img" alt="">
            </div>
            <!--text-->
            <div class="title_text">
              <span>{{item.title}}</span>
            </div>
            <div class="text_bom">
              <span class="b1 el-icon-video-play">{{item.watch}}万</span>
              <span class="b2 el-icon-user">{{item.body}}</span>
            </div>
          </div>
        </div>
      </div>
      <!--分页-->
      <div class="page">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="total, prev, pager, next"
          :total="tableData.length">
        </el-pagination>
      </div>
    </div>
</template>

<script>
    export default {
      name: "Knowledge",
      data(){
        return{
          currentPage: 1, //初始页
          pageSize: 15 ,    //每页的数据
          tableData:[{}],
          KnowledgeData:[{}],
        }
      },
      methods:{
        // 初始页currentPage、初始每页数据数pagesize和数据data
        handleSizeChange: function (size) {
          this.pagesize = size;
          console.log(this.pagesize)  //每页下拉显示数据
        },
        handleCurrentChange: function (currentPage) {
          this.currentPage = currentPage;
          console.log(this.currentPage)  //点击第几页
        },
        getKnowledgeByWatch(){
           let _this = this;
           this.$axios.get('http://localhost:8066/news/hotClass/'+1).then(function (res) {
             _this.KnowledgeData = res.data
             console.log(_this.KnowledgeData)
           }).catch(function (err) {
             alert("查询失败")
           })
        },
        getKnowledge(){
          let _this = this;
          this.$axios.get('http://localhost:8066/news/getClass/'+1).then(function (res) {
            _this.tableData = res.data
            console.log(_this.tableData)
          }).catch(function (err) {
            alert("查询失败")
          })
        },
      },
      mounted() {
        this.getKnowledgeByWatch()
        this.getKnowledge()
      }
    }
</script>

<style scoped>
  .page{
    float: left;
  }
  .content{
    width: 1300px;
    height: 350px;
  }
  .bom1{
    width: 1300px;
    height: 1150px;
  }
  .text_bom span{
    font-size: 13px;
    color: gray;
  }
  .text_bom .b2{
    margin-left: 50px;
  }
  .title{
    margin-top: 50px;
  }
  .card-title-text:before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    display: block;
    width: 2px;
    height: 22px;
    margin-top: -9px;
    border-radius: 1.5px;
    background: #ff1e66;
  }
  .card-title-text {
    position: relative;
    width: 50%;
    height: 40px;
    padding: 0 0 0 12px;
    font-size: 29px;
    color: #000;
  }
  .ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  a{
    text-decoration: none;
  }
  .card_list{
    margin-top: 25px;
    float: left;
    margin-left: 25px;
  }
  .img_list{
    width: 220px;
    height: 300px;
    overflow: hidden;
    border-radius: 5px;
  }
  .img_list img{
    display: block;
    transition: all 1s;
    width: 220px;
    height: 300px;
    border-radius: 5px;
  }
  .img_list img:hover{
    transform: scale(1.1);
  }
  .title_text{
    margin-top: 5px;
    font-size: 15px;
    width: 210px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
